package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.Process;
import com.stylefeng.guns.modular.system.service.IProcessService;

/**
 * 请假规定控制器
 *
 * @author fengshuonan
 * @Date 2019-06-19 17:10:58
 */
@Controller
@RequestMapping("/process")
public class ProcessController extends BaseController {

    private String PREFIX = "/system/process/";

    @Autowired
    private IProcessService processService;

    /**
     * 跳转到请假规定首页
     */
    @RequestMapping("/process_index")
    public String index() {
        return PREFIX + "process.html";
    }

    /**
     * 跳转到添加请假规定
     */
    @RequestMapping("/process_add")
    public String processAdd() {
        return PREFIX + "process_add.html";
    }

    /**
     * 跳转到修改请假规定
     */
    @RequestMapping("/process_update/{processId}")
    public String processUpdate(@PathVariable Integer processId, Model model) {
        Process process = processService.selectById(processId);
        model.addAttribute("item",process);
        LogObjectHolder.me().set(process);
        return PREFIX + "process_edit.html";
    }

    /**
     * 获取请假规定列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return processService.selectList(null);
    }

    /**
     * 新增请假规定
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Process process) {
        processService.insert(process);
        return SUCCESS_TIP;
    }

    /**
     * 删除请假规定
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer processId) {
        processService.deleteById(processId);
        return SUCCESS_TIP;
    }

    /**
     * 修改请假规定
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Process process) {
        processService.updateById(process);
        return SUCCESS_TIP;
    }

    /**
     * 请假规定详情
     */
    @RequestMapping(value = "/detail/{processId}")
    @ResponseBody
    public Object detail(@PathVariable("processId") Integer processId) {
        return processService.selectById(processId);
    }
}
